<?
if (!isset($r)) $r = "../";
require_once($r."_engine/c_account.php");

$account = GetActiveAccount(false);
if ($account == NULL) return;

$categories = new CCategories($account);

if (@$do_remove)
{
	$categories->Delete(@$f_c_ids);
}
?>
<div id="id_category_editor">

<form name="form_categories">
<input type="Hidden" name="do_remove" value="0">

<table cellspacing="5" cellpadding="0" style="margin-left: 5;">
<tr><td colspan="2"><span class="textStd">


<?
require_once($r."_inc/c_table_generator.php");
$tg = new CTableGenerator();
$tg->style = "width: 100%; xmargin-right: -10; margin-left: 0;";
$tg->widths[0] = "25";

$a = array();
$a[] = "";
$a[] = "Category";
$tg->PrintHeader($a);

/* TODO: Move to category class definition file */
/* TODO: Intgrate category type ligic in class  */
define("CATEGORY_TYPE_NONE",	0x0);
define("CATEGORY_TYPE_SYS",		0x1);
define("CATEGORY_TYPE_USER",	0x2);

function print_categories_rows($type)
{
	global $categories, $tg;
	
	foreach ($categories->names as $id => $name)
	{
		$type_act = ($id == $categories->default_category_id ?
			CATEGORY_TYPE_SYS : CATEGORY_TYPE_USER);
			
		if ($type != $type_act) continue;

		$a = array();

		// Column: [checkbox]
		if ($type_act == CATEGORY_TYPE_SYS)
			$a[] = '';
		else
			$a[] = '<input type="Checkbox" name="f_c_ids[]" value="'.$id.'">';
			
		// Column: Category
		if ($type_act == CATEGORY_TYPE_SYS) {
			$name = '<span style="color: #BBBBBB;">'.$name.'</span>';
		}
		$a[] = $name;
		
		$tg->PrintRow($a);
	}
}

print_categories_rows(CATEGORY_TYPE_SYS);
print_categories_rows(CATEGORY_TYPE_USER);

$tg->PrintFooter();
?>

</td></tr>

<tr>
	<td colspan="2"><span class="textStd">
		<input type="Button" value="Delete" onClick="javascript: on_remove_category();"
			class="button2" onMouseOver="this.className='button2_act'" onMouseOut="this.className='button2'">
	</td>
</tr>
</table>
</form>

<script type="text/javascript" language="JavaScript">
function on_remove_category() {
	if (confirm("Are you sure you want to delete selected category(s)?")) {
		var f = document.form_categories;
		f.do_remove.value = 1;

		ajaxLoadDataToInnerHtml(
			ajaxAppendToUrl(
				g_site_root_ajax+"/members/defaults_ce.php",
				ajaxFormToUrl("form_categories")
			),
			"id_category_editor");
	}
}
</script>
</div>